package com.liqi.frame.comm.dto;

import com.liqi.frame.comm.enums.ResultEnum;
import lombok.Data;

import java.util.List;

/**
 * Layui表格数据对象
 * @author liqi on 2017/8/28.
 * liqiwork@qq.com
 */
@Data
public final class LayuiTableData<List> {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * message
     */
    private String msg;
    /**
     * 数据总条数
     */
    private Long count;
    /**
     * 数据
     */
    private List data;

    public LayuiTableData(ResultEnum resultEnum, List data, Long count) {
        this.code = resultEnum.getCode();
        this.data = data;
        this.count = count;
    }

    public LayuiTableData(ResultEnum resultEnum, String msg) {
        this.code = resultEnum.getCode();
        this.msg = msg;
    }

    public LayuiTableData(ResultEnum resultEnum, String msg, List data, Long count) {
        this.code = resultEnum.getCode();
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public LayuiTableData(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMessage();
    }

    public static LayuiTableData success(){
        return new LayuiTableData<>(ResultEnum.SUCCESS);
    }
    public static LayuiTableData success(Object data, Long count){
        return new LayuiTableData<>(ResultEnum.SUCCESS, data, count);
    }
    public static LayuiTableData success(String msg, Object data, Long count){
        return new LayuiTableData<>(ResultEnum.SUCCESS, msg, data, count);
    }

    public static LayuiTableData failure(){
        return new LayuiTableData<>(ResultEnum.FAILURE);
    }
    public static LayuiTableData failure(Object data, Long count){
        return new LayuiTableData<>(ResultEnum.FAILURE, data, count);
    }
    public static LayuiTableData failure(String msg, Object data, Long count){
        return new LayuiTableData<>(ResultEnum.FAILURE, msg, data, count);
    }
}
